#include"studentc.h"
using std::ostream;
using std::endl;
using std::istream;
using std::string;

//公有方法
double Student::Average() const
{
    if (scores.size()>0)
    {
        return scores.sum()/scores.size();
    }
    else
    {
        return 0;
    }
}
const string & Student::Name() const
{
    return name;
}
double & Student::operator[](int i)
{
    return scores[i];
}
double Student::operator[](int i) const
{
    return scores[i];
}
//私有方法
ostream &Student::arr_out(ostream &os) const
{
    int lim=scores.size();
    if (lim>0)
    {
        for (int i = 0; i < lim; i++)
        {
            os<<scores[i]<<" ";
            if (1%5==4)
            {
                os<<endl;
            }
        }
    }
    else
    {
        os<<"empty array";
    }
    return os;
}
//友元函数
//使用字符串版本operator>>()
istream & operator>>(istream &is,Student &stu)
{
    is>>stu.name;
    return is;
}
//使用字符串友元getline(ostream &,const string &)
istream &getline(istream &is,Student &stu)
{
    getline(is,stu.name);
    return is;
}
//使用字符串版本operator<<()
ostream & operator<<(ostream &os,const Student &stu)
{
    os<<"Scores for "<<stu.name<<":\n";
    stu.arr_out(os);
    return os;
}